package com.common.demo.jeecg;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: hua
 * @Date: 2023/05/29 18:15
 * @version: v1.0
 * @Description: TODO
 */
@ControllerAdvice("com.common.demo.jeecg")
public class MyExceptionHandler {
    /**
     * 捕获CustomException
     *
     * @param e
     * @return json格式类型
     */
    /*@ResponseBody
    @ExceptionHandler({JeecgBootException.class}) //指定拦截异常的类型
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) //自定义浏览器返回状态码
    public Map<String, Object> customExceptionHandler(JeecgBootException e) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 500);
        *//*
        map.put("code", e.);
        map.put("msg", e.getMsg());*//*
        //Result.error(e.getMessage())
        return map;
    }*/
    @ExceptionHandler(JeecgBootException.class)
    @ResponseBody
    public Result errorJeecg(JeecgBootException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    /*NullPointerException.class
    Exception.class*/
}
